Fix: required validation for multi-select ComboBox (#9788)#9792
Fix: required validation for multi-select ComboBox (#9788)#9792devongovett merged 5 commits intoadobe:mainfrom
Conversation
| let validation = useFormValidationState({ | ||
| ...props, | ||
| value: useMemo(() => Array.isArray(displayValue) && displayValue.length === 0 ? null : ({inputValue, value: displayValue as any, selectedKey}), [inputValue, selectedKey, displayValue]) | ||
| value: useMemo(() => ({inputValue, value: displayValue as any, selectedKey}), [inputValue, selectedKey, displayValue]) |
There was a problem hiding this comment.
I don't think this is correct. If the value is empty, validate should not be called. This should be handled by isRequired.
| ); | ||
| let comboBoxProps = removeDataAttributes(props); | ||
| if (props.selectionMode === 'multiple') { | ||
| delete comboBoxProps.isRequired; |
There was a problem hiding this comment.
Can we handle this inside the useComboBox hook?
| values = [null]; | ||
| // For multiple mode, add required to the hidden input when no values selected | ||
| let required = props.selectionMode === 'multiple' && props.isRequired; | ||
| inputs = [<input key="empty" type="hidden" name={name} form={props.form} value="" required={required} />]; |
There was a problem hiding this comment.
Does this actually prevent form submission? I thought type="hidden" did not support required. We may need to use a type="text" with display: none here.
…required handling
|
I've addressed the review feedback. Please take another look.
…On Tue, Mar 17, 2026 at 12:28 AM Devon Govett ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/react-aria-components/src/ComboBox.tsx
<#9792 (comment)>
:
> @@ -210,12 +214,14 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
if (name && formValue === 'key') {
let values: (Key | null)[] = Array.isArray(state.value) ? state.value : [state.value];
if (values.length === 0) {
- values = [null];
+ // For multiple mode, add required to the hidden input when no values selected
+ let required = props.selectionMode === 'multiple' && props.isRequired;
+ inputs = [<input key="empty" type="hidden" name={name} form={props.form} value="" required={required} />];
Does this actually prevent form submission? I thought type="hidden" did
not support required. We may need to use a type="text" with display: none
here.
—
Reply to this email directly, view it on GitHub
<#9792 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BBXSL3L7UMW6F4K53IMLX5D4RBFFPAVCNFSM6AAAAACWRZRUUCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTSNJVHE4DKOBXGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
…box-multiselect-required
…box-multiselect-required
|
Added a commit to fix the tests and simplify the approach a little. I realized that we don't track the validation state for these hidden inputs, so we weren't displaying the validation errors properly. Instead of doing that, we can instead simply mark the visible text field as required but only if no items are selected. |
|
@Nawaz-B-04 you'll need to sign the CLA |
Closes #9788
✅ Pull Request Checklist:
📝 Test Instructions:
selectionMode="multiple"andisRequired.Expected result:
Form submission succeeds when items are selected.
Expected result:
Form validation prevents submission due to required constraint.
🧢 Your Project:
Personal open source contribution.